package com.briup.pts.service.impl;

import com.briup.pts.VM.CountVM;
import com.briup.pts.VM.StringVM;
import com.briup.pts.mapper.*;
import com.briup.pts.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class AnalysisServiceImpl implements AnalysisService {
    @Autowired
    ManagerFenceHouseMapper managerFenceHouseMapper;
    @Autowired
    ManagerAnimalMapper managerAnimalMapper;
    @Autowired
    ManagerDiseaseMapper managerDiseaseMapper;
    @Autowired
    IssueRecordMapper issueRecordMapper;
    @Autowired
    ManagerHurdlesMapper managerHurdlesMapper;
    @Autowired
    AnalysisMapper analysisMapper;

    @Override
    public CountVM count() {
        CountVM countVM = new CountVM();
        // 定义一下名字
        List<String> nameList = new ArrayList<>();
        Collections.addAll(nameList, "栏舍", "栏圈", "动物", "冷库", "员工");
        countVM.setName(nameList);
        // 获取每个部分的统计数据
        // 两种写法：1、使用各个模块的查询全部进行统计size （）
//        managerDiseaseMapper.countByExample()...
        //         2、使用一条SQL语句组装结果集（讲解的时候使用这个）
        countVM.setValue( analysisMapper.count());
        return countVM;
    }

    @Override
    public CountVM countSales() {
        CountVM countVM = new CountVM();
        ArrayList<Object> monthList = new ArrayList<>();
        countVM.setName(Arrays.asList( "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"));
        countVM.setValue(analysisMapper.countSales(2023));
        return countVM;
    }

    @Override
    public Map<String, Integer> countDisease() {
        Map<String, Integer> map = new HashMap<>();
        List<StringVM> stringVMS = analysisMapper.contDisease();
//        System.out.println("stringVMS = " + stringVMS);
        for (StringVM stringVM : stringVMS) {
            map.put(stringVM.getName(),stringVM.getValue());
        }
        return map;
    }

    @Override
    public Map<String, Integer> countWeight() {
        Map<String, Integer> map = new HashMap<>();
        List<StringVM> stringVMS = analysisMapper.countWeight();
        System.out.println("stringVMS = " + stringVMS);
        for (StringVM stringVM : stringVMS) {
            map.put(stringVM.getName(),stringVM.getValue());
        }
        return map;
    }


//    @Override
//    public Map<String, List<Object>> countNum() {
//        ArrayList<Object> nameList = new ArrayList<>();
//        Collections.addAll(nameList,"栏舍", "栏圈", "动物", "冷库", "员工");
//        List<Object> countList = managerFenceHouseMapper.countAllResources();
//        Map<String, List<Object>> Map = new HashMap<>();
//        Map.put("name",nameList);
//        Map.put("value", countList);
//        return Map;
//    }
//
//    @Override
//    public Map<String, Integer> countWeight() {
//        Map<String, Integer> map = new HashMap<>();
//        ManagerAnimalExample managerAnimalExample1 = new ManagerAnimalExample();
//        managerAnimalExample1.createCriteria().andAWeightLessThan("30");
//        long l = managerAnimalMapper.countByExample(managerAnimalExample1);
//        map.put("30以下", (int) l);
//        ManagerAnimalExample managerAnimalExample2 = new ManagerAnimalExample();
//        managerAnimalExample2.createCriteria().andAWeightBetween("30","50");
//        long l1 = managerAnimalMapper.countByExample(managerAnimalExample2);
//        ManagerAnimalExample managerAnimalExample3 = new ManagerAnimalExample();
//        managerAnimalExample3.createCriteria().andAWeightGreaterThan("50");
//        long l2 = managerAnimalMapper.countByExample(managerAnimalExample3);
//        map.put("50以上", (int) l1);
//        map.put("30~50", (int) l1);
//        return map;
////        return managerAnimalMapper.countWeight();
//    }
//
//    @Override
//    public Map<String, Long> countDisease() {
//        managerDiseaseMapper.countDisease();
//        return null;
//    }

//    @Override
//    public Map<String, List<Object>> countSales() {
//        // 月份列表
//        List<Object> monthList = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
//
//        // 构建并返回结果Map
//        Map<String, List<Object>> resultMap = new HashMap<>();
//        resultMap.put("name", monthList);
//        List<Object> valueList = null;
//        resultMap.put("value", valueList);
//
//        return resultMap;
//    }
}
